import {defineStore} from "pinia";
import {LawyerApi} from "@/api/lawyer/index.js";


export const LawyerStores = defineStore('lawyer', {
    state: () => ({
        lawyerList: [],
        pageInfo: {
            page: 1,
            size: 10,
            total: 0,
            totalPage: 0
        }

    }),
    actions: {
        pageInfo: undefined,
        async pagelist( params ={}) {
            try {
                const response = await LawyerApi.pagelist({
                    page: params.page || this.pageInfo.page,
                    size: params.size || this.pageInfo.size,
                    ...params
                });
                if( response)
                {
                    this.lawyerList = Array.isArray(response.data?.records) ? response.data.records : [];
                    this.pageInfo = {
                        page: response.data.pageNumber || 1,
                        size: response.data.pageSize || 10,
                        total: response.data.totalRow || 0,
                        totalPage: response.data.totalPage || 0
                    };
                    return response;

                }
            }catch (error){
                console.error('获取列表失败:', error);
                return error;
            }
        }
    }
})
